package com.zhy.generator.codegen.mybatis.javahelper;

import com.zhy.generator.codegen.api.CommentGenerator;
import com.zhy.generator.codegen.dom.java.CompilationUnit;
import com.zhy.generator.codegen.dom.java.FullyQualifiedJavaType;
import com.zhy.generator.codegen.dom.java.JavaVisibility;
import com.zhy.generator.codegen.dom.java.TopLevelClass;
import com.zhy.generator.codegen.mybatis.AbstractJavaGenerator;
import com.zhy.generator.codegen.mybatis.javahelper.elements.*;

import java.util.ArrayList;
import java.util.List;

import static com.zhy.generator.codegen.util.Messages.getString;

/**
 * @author 源
 */
public class JavaHelperGenerator extends AbstractJavaGenerator {
    @Override
    public List<CompilationUnit> getCompilationUnits() {
        progressCallback.startTask(getString("Progress.14", introspectedTable.getFullyQualifiedTable()));
        CommentGenerator commentGenerator = context.getCommentGenerator();

        FullyQualifiedJavaType type = new FullyQualifiedJavaType(introspectedTable.getHelperType());
        TopLevelClass tlc = new TopLevelClass(type);
        tlc.setVisibility(JavaVisibility.PUBLIC);
        commentGenerator.addJavaFileComment(tlc);

        addPoToVO(tlc);
        addPoToVOBatch(tlc);
        addDoToVOBatch(tlc);
        addDoToVO(tlc);
        addAddParamToPO(tlc);
        addEditParamToPO(tlc);
        List<CompilationUnit> answer = new ArrayList<CompilationUnit>();
        answer.add(tlc);
        return answer;
    }

    private void addEditParamToPO(TopLevelClass tlc) {
        AbstractJavaHelperMethodGenerator generator = new EditParamToPOMethodGenerator();
        initializeAndExecuteGenerator(generator,tlc);
    }

    private void addAddParamToPO(TopLevelClass tlc) {
        AbstractJavaHelperMethodGenerator generator = new AddParamToPOMethodGenerator();
        initializeAndExecuteGenerator(generator,tlc);
    }

    private void addDoToVO(TopLevelClass tlc) {

    }

    private void addDoToVOBatch(TopLevelClass tlc) {

    }

    private void addPoToVOBatch(TopLevelClass tlc) {
        AbstractJavaHelperMethodGenerator generator = new PoToVOBatchMethodGenerator();
        initializeAndExecuteGenerator(generator,tlc);
    }

    private void addPoToVO(TopLevelClass tlc) {
        AbstractJavaHelperMethodGenerator generator = new PoToVOMethodGenerator();
        initializeAndExecuteGenerator(generator,tlc);
    }
    protected void initializeAndExecuteGenerator(AbstractJavaHelperMethodGenerator methodGenerator, TopLevelClass tlc) {
        methodGenerator.setContext(context);
        methodGenerator.setIntrospectedTable(introspectedTable);
        methodGenerator.setProgressCallback(progressCallback);
        methodGenerator.setWarnings(warnings);
        methodGenerator.addHelperElements(tlc);
    }

}
